package com.wmd102.mediademo;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import com.wmd102.encode.LameEncoder;

import java.io.File;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = MainActivity.class.getSimpleName();

    private LameEncoder mLameEncoder;
    // Used to load the 'native-lib' library on application startup.
//    static {
//        System.loadLibrary("native-lib");
//    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Example of a call to a native method
        TextView tv = findViewById(R.id.sample_text);

        mLameEncoder = new LameEncoder();
        tv.setText(mLameEncoder.stringFromJNI() + "\n"
                + mLameEncoder.getLameVersion()+ "\n"
                + mLameEncoder.getFDKAACVersion()+ "\n");

        encodePCM2MP3();
    }

    private void encodePCM2MP3() {
        File pcmFile = new File(getExternalFilesDir(null), "input.pcm");
        File mp3File = new File(getExternalFilesDir(null), "output.mp3");
        Log.d(TAG, "encodePCM2MP3 pcmFile:"+pcmFile.getAbsolutePath());
        Log.d(TAG, "encodePCM2MP3 mp3File:"+mp3File.getAbsolutePath());
        mLameEncoder.encode(pcmFile.getAbsolutePath(), mp3File.getAbsolutePath(), 44100, 2, 128);
    }

    /**
     * A native method that is implemented by the 'native-lib' native library,
     * which is packaged with this application.
     */
//    public native String stringFromJNI();
//    public native String getLameVersion();
//    public native String getFDKAACVersion();
}
